/**
 * 
 */
package com.avidys.gwt.wom.model;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.i18n.client.DateTimeFormat;

/**
 * A given site test: ping traceroute...
 * @author jm
 *
 */
/**
 * Site as an overlay JS as an overlay type
 */


public class SiteTestPoint extends JavaScriptObject {

	// Overlay types always have protected, zero-arg ctors
	protected SiteTestPoint() { } 

	private static enum Method { PING, TRACEROUTE, GET, POST };

	// Typically, methods on overlay types are JSNI
	public final native String getSiteName () /*-{ return this.SiteName ; }-*/;
	public final native String getMethod () /*-{ return this.Method ; }-*/;
	public final native String getDateStart() /*-{ return this.DateStart; }-*/;
	public final native String getDateEnd() /*-{ return this.DateEnd; }-*/;
	public final native String getElapsedTime() /*-{ return this.ElapsedTime; }-*/;
	public final native String getResult() /*-{ return this.Result; }-*/;
	public final native String getDump() /*-{ return this.Dump; }-*/;

	public static final native SiteTestPoint getSiteTestPoint (String json) /*-{
	  return eval(json);
	}-*/;

	public static final native JsArray<SiteTestPoint> getSiteTestPoints (String json) /*-{
	  return eval(json);
	}-*/;
	
	public final void listSiteTestPoint(JsArray<SiteTestPoint> cs){
		for (int i = 0, n = cs.length(); i < n; ++i) {
			GWT.log(cs.get(i).getStr(),null);
		}
	}
	
	public final  String getStr() {
		String s=getSiteName()+" "+getMethod();
		return s;
	}

//	private Method method;
//	private Date dateStart;
//	private Date dateEnd;
//	private String result;
//	private String dump;
//	
	/*
       Method.PING
    for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
        System.out.println(e.nextElement());

    }
	 */

//	public SiteTestPoint(Method method, Date dateStart, Date dateEnd, String result,
//			String dump) {
//		super();
//		this.method = method;
//		this.dateStart = dateStart;
//		this.dateEnd = dateEnd;
//		this.result = result;
//		this.dump = dump;
//
//		switch (method){
//		case PING: break;
//		default: break;
//		}
//	}

	/**
	 * get client's time zone
	 * @param type
	 * @return
	 */
	private final String getTimeZone(int type) {
		Date today = new Date();
		String timezone = null;

		switch (type) {
		case 1: // date timeZoneMinOffset in minutes
			timezone = Integer.toString(today.getTimezoneOffset()); //like "420"
			break;
		case 2: // time zone RFC822
			timezone = DateTimeFormat.getFormat("Z").format(today); //like "-0700"
			break;
		case 3: //time zone TextShort
			timezone = DateTimeFormat.getFormat("v").format(today); //like "GMT-07:00"
			break;
		case 4: //time zone Name 

			//THIS WONT COMPILE - WORKS IN DEBUGGER - this will not work on client side
			//TimeZone tz = TimeZone.getDefault();
			//timezone = tz.getID(); //like "America/Vancouver"
			timezone = DateTimeFormat.getFormat("z").format(today); //like "GMT-07:00";

			break;
		case 5: //timezone TextLong
			timezone = DateTimeFormat.getLongDateTimeFormat().format(today); //like "March 22, 2008 5:39:22 PM GMT-07:00"
			break;
		}

		return timezone;
	}

/*
	void gmtsERVER (){
//		get the servers GMT Time
		Date date = new Date();
		TimeZone tzGMT = TimeZone.getTimeZone("GMT");
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		cal.setTimeZone(tzGMT);

//		GMT hour and minute
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int min = cal.get(Calendar.MINUTE);

		System.out.println("now: h:" + hour + " m:" + min);
	}
*/
	final void  tesDate(){
		Date today = new Date();

		// prints Tue Dec 18 12:01:26 GMT-500 2007 in the default locale.
		GWT.log(today.toString(), null);

		// 	prints 12/18/07 in the default locale
		GWT.log(DateTimeFormat.getShortDateFormat().format(today), null);

//		prints December 18, 2007 in the default locale
		GWT.log(DateTimeFormat.getLongDateFormat().format(today), null);

//		prints 12:01 PM in the default locale
		GWT.log(DateTimeFormat.getShortTimeFormat().format(today), null);

//		prints 12:01:26 PM GMT-05:00 in the default locale
		GWT.log(DateTimeFormat.getLongTimeFormat().format(today), null);

//		prints Dec 18, 2007 12:01:26 PM in the default locale
		GWT.log(DateTimeFormat.getMediumDateTimeFormat().format(today), null);
	}
}
